package thread.atomic;

import java.util.Random;

/**
 * @author liweimin
 * @date 2021/4/29 16:23
 * @since
 */
public class IndicatorTest {

    public static void main(String[] args) {
        Indicator instance = Indicator.getInstance();

        for (int i = 0; i < 1000; i++) {
            new Thread(() -> {
                instance.newRequest();
                int nextInt = new Random().nextInt();
                if (nextInt % 2 == 0) {
                    instance.handleSuccess();
                } else {
                    instance.handleFailure();
                }
            }).start();
        }

        //主线程打印需要等待所有线程都执行完毕
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("请求总数为：" + instance.getRequestCount());
        System.out.println("成功总数为：" + instance.getSuccessCount());
        System.out.println("失败总数为：" + instance.getFailureCount());
    }
}
